﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Threading;

namespace WPFThreadingTest
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window,INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            ThreadPool.QueueUserWorkItem(x =>
            {
                Thread.Sleep(5000);
                while (true)
                {
                    Thread.Sleep(1000);
                    TestText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                }
            });
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private string testText;
        public string TestText
        {
            get { return testText; }
            set
            {
                testText = value;
                PropertyChanged?.BeginInvoke(this, new PropertyChangedEventArgs(nameof(TestText)), null, null);
            }
        }
    }
}
